import { createContext, useEffect, useState } from 'react';
const regExp_phoneNumber = new RegExp(/^(\+?0?86\-?)?1[3456789]\d{9}$/);

const formRule = {
    realName: [{ required: true, message: '姓名不能为空' }],
    qqAccount: [{ required: true, message: 'qq号不能为空' }],
    weiboNickName: [{ required: true, message: '微博昵称不能为空' }],
    weiboFollowerQuantity: [{ required: true, message: '微博粉丝数不能为空' }],
    xiaohongshuNickName: [{ required: true, message: '小红书昵称不能为空' }],
    xiaohongshuFollowerQuantity: [{ required: true, message: '小红书粉丝数不能为空' }],
    tiebaNickName: [{ required: true, message: '贴吧昵称不能为空' }],
    tiebaFollowerQuantity: [{ required: true, message: '贴吧粉丝数不能为空' }],
    agencyName: [{ required: true, message: '代理机构名称不能为空' }],
    agentName: [{ required: true, message: '代理人姓名不能为空' }],
    agentPosition: [{ required: true, message: '代理人职位不能为空' }],
    phoneNumber: [
        {
            required: true,
            validator: (rule, val) => {
                if (!val) {
                    return Promise.reject('手机号不能为空');
                }
                if (!regExp_phoneNumber.test(val)) return Promise.reject('手机号格式不正确');
                return Promise.resolve();
            },
        },
    ],
};
export type ApplySettledInContextType = {
    /**表单验证规则 */
    formRules: typeof formRule;
};
export const ApplySettledInContext = createContext<ApplySettledInContextType>(undefined);
const useApplySettledInContext = () => {
    const [formRules] = useState(formRule);

    return {
        formRules,
    };
};

export { useApplySettledInContext };
